package com.hw.servlet;

import com.google.gson.Gson;

import javax.servlet.RequestDispatcher;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Map;

@WebServlet({"/hh","/sesstion2"})/*使用注解来配置Servlet*/
public class DServlet extends javax.servlet.http.HttpServlet {
    protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
      /* request.setCharacterEncoding("UTF-8");//更改request传入的编码格式

        Enumeration<String> enumeration=request.getParameterNames();//获取表单元素的所有的传入内容
        while (enumeration.hasMoreElements()){
           String key=enumeration.nextElement();
            System.out.println(key+"===="+request.getParameter(key));
        }
        RequestDispatcher dispatcher= request.getRequestDispatcher("/index.jsp");//在内部进行重新定向，转到本项目中
        dispatcher.include(request,response);//在内部跳装，进行合并
        dispatcher.forward(request,response);
        System.out.println("dd");*/
        response.setCharacterEncoding("utf-8");
        response.setContentType("application/json;utf-8");
        HttpSession session=request.getSession();
        ArrayList<String> j= (ArrayList<String>) session.getAttribute("shop");
        Gson gson=new Gson();
        PrintWriter ij=response.getWriter();
        ij.print(gson.toJson(j));

    }

    protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
      doPost(request,response);
    }

}
